package com.link.base.base.mvg.service;

import com.link.base.base.cmqres.model.CmqRes;
import com.link.base.base.cmqres.service.CmqResService;
import com.link.base.base.mvg.model.Mvg;
import com.link.core.cllog.LCLogger;
import com.link.core.mq.util.MqUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * @author unknown
 * @date unknown
 * @comments mvg操作之后，后续操作
 */
@Service
public class AfterMvgOperaServiceImpl implements AfterMvgOperaService {

    @Resource
    private CmqResService cmqResService;

    @Override
    public void afterOperation(Mvg mvg, String maperName) throws Exception {
        CmqRes cmqRes = new CmqRes();
        List<CmqRes> cmqResList = cmqResService.queryAll(cmqRes);

        switch (maperName) {
            case "accntPostnMvgMapper":
            case "accntPostnMvg":
            case "accntPriceListMvgMapper":
            case "accntPriceListMvg":
                if (cmqResList.size() > 0) {
                    try {
                        String message1 = "AccountSyncl;{\"action\":\"Update\",\"objectId\":\"";
                        String message2 = "\"}";
                        String message = message1 + mvg.getMvgParentId() + message2;
                        String topicName = cmqResList.get(0).getQueueName();
                        MqUtil.sendCmqTopic(topicName, message);
                    } catch (Exception e) {
                        LCLogger.withException(e);
                    }
                }
                break;
            case "accntLov1MvgMapper":
            case "accntLov1Mvg":
            case "accntLov2MvgMapper":
            case "accntLov2Mvg":
                if (cmqResList.size() > 0) {
                    try {
                        String message1 = "StoreSyncl;{\"action\":\"Update\",\"objectId\":\"";
                        String message2 = "\"}";
                        String message = message1 + mvg.getMvgParentId() + message2;
                        String topicName = cmqResList.get(0).getQueueName();
                        MqUtil.sendCmqTopic(topicName, message);
                    } catch (Exception e) {
                        LCLogger.withException(e);
                    }
                }
                break;
            default:
                break;
        }
    }

}
